import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: '/main',
    },
    {
      path: '/login',
      name: 'login',
      component: (resolve)=>require(['../Login.vue'],resolve),
    },
    {
      path:'/main',
      component:(resolve) => require(['../rdView/Main.vue'], resolve),
      redirect: '/main/test',
      meta:{
        requiresAuth:true
      },
      children:[
        /*测试中心*/
        {
          path:'/main/test',
          component:(resolve) => require(['../rdView/test/Index.vue'], resolve),
          redirect: '/main/test/single',
          meta:{
            requiresAuth:true
          },
          children:[
            /*单接口测试*/
            {
              path:'/main/test/single',
              component:(resolve) => require(['../rdView/test/single/Index.vue'], resolve),
              meta:{ requiresAuth:true }
            },
            /*集成测试*/
            {
              path:'/main/test/integrate',
              component:(resolve) => require(['../rdView/test/integrate/Index.vue'], resolve),
              meta:{ requiresAuth:true },
              redirect: '/main/test/integrate/list',
              children: [
                {
                  name: "list",
                  path:'/main/test/integrate/list',
                  component:(resolve) => require(['../rdView/test/integrate/component/List.vue'], resolve),
                  meta:{ requiresAuth:true }
                },
                {
                  name: "addOrUpdate",
                  path:'/main/test/integrate/addOrUpdate',
                  component:(resolve) => require(['../rdView/test/integrate/component/AddOrUpdate.vue'], resolve),
                  meta:{ requiresAuth:true }
                }
              ]
            },
            /*用例测试*/
            {
              path:'/main/test/useCase',
              component:(resolve) => require(['../rdView/test/useCase/Index.vue'], resolve),
              meta:{ requiresAuth:true }
            },
            /*配置管理*/
            {
              path:'/main/test/config',
              component:(resolve) => require(['../rdView/test/config/system.vue'], resolve),
              meta:{ requiresAuth:true }
            },
            /*超時配置*/
            {
              path:'/main/test/time',
              component:(resolve) => require(['../rdView/test/config/interface.vue'], resolve),
              meta:{ requiresAuth:true }
            },
            /*歷史記錄配置*/
            {
              path:'/main/test/history',
              component:(resolve) => require(['../rdView/test/config/history.vue'], resolve),
              meta:{ requiresAuth:true }
            }
          ]
        },
      ]
    }
  ],
  // mode:'history'
})

router.beforeEach((to,form,next)=>{
  if(to.fullPath === '/login'){
    sessionStorage.clear();
    next();
  }else{
    next();
  }
});

export default router;
